import {
  h
} from 'snabbdom'
import {
  noop
} from '../util/index'
import Watcher from '../observer/watcher'
import {
  patch
} from 'web/runtime/patch'
import {
  query
} from 'web/util/index'

export function mountComponent(vm, el) {
  let updateComponent = () => {
    const vnode = vm.$options.render.call(vm, h)
    if (vm._vnode) {
      patch(vm._vnode, vnode)
    } else {
      patch(query(el), vnode)
    }
    vm._vnode = vnode
  }
  new Watcher(vm, updateComponent, noop)
}

export function lifecycleMixin(Vue) {
  Vue.prototype._update = function (vnode) {
    const vm = this
    if (vm._vnode) {
      path(vm._vnode, vnode)
    } else {
      patch(query(vm.$el), vnode)
    }
    vm._vnode = vnode
  }
}